package com.antsing.client;

import com.antsing.entity.ChannelProp;
import com.antsing.entity.Constant;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.Attribute;
import io.netty.util.concurrent.EventExecutorGroup;

import java.util.Date;

public class ClientHandler2 extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Attribute<ChannelProp> attr = ctx.channel().attr(Constant.NETTY_CHANNEL_KEY1);
        ChannelProp channelProp = attr.get();
        if(channelProp == null){
            channelProp = new ChannelProp("antsing_active2",new Date());
            attr.setIfAbsent(channelProp);
        }else {
            System.out.println("channelActive2 attributeMap 中是有值的");
            System.out.println(channelProp.getName() + "=======" + channelProp.getCreateDate());
        }
        System.out.println("ClientHandler2 Active");
        //ctx.fireChannelActive();
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Attribute<ChannelProp> attr = ctx.channel().attr(Constant.NETTY_CHANNEL_KEY1);
        ChannelProp channelProp = attr.get();
        if(channelProp == null){
            channelProp = new ChannelProp("antsing_read2",new Date());
            attr.setIfAbsent(channelProp);
        }else {
            System.out.println("channelRead2 attributeMap 中是有值的");
            System.out.println(channelProp.getName() + "=======" + channelProp.getCreateDate());
        }
        System.out.println("ClientHandler2 read");
       // ctx.fireChannelActive();
    }
}
